package de.piratech.dasding.data.database.mongo.data;

import net.vz.mongodb.jackson.DBRef;
import de.piratech.dasding.data.AbstractCategory;
import de.piratech.dasding.data.User;
import de.piratech.dasding.data.database.mongo.AbstractMongoDB.COLLECTIONS;

public class AbstractMongoCategory<T extends AbstractCategory> extends
    AbstractMongoDataObject<T> {

  DBRef<MongoUser, String> createdByRef;

  public AbstractMongoCategory(T object) {
    super(object);
    if (object != null && object.getCreatedBy() != null) {
      createdByRef = new DBRef<MongoUser, String>(
          object.getCreatedBy().getId(), COLLECTIONS.USER_COLLECTION.getName());
    }
  }

  public String getName() {
    return getDataObject().getName();
  }

  public void setName(String pName) {
    getDataObject().setName(pName);
  }

  public String getDescription() {
    return getDataObject().getDescription();
  }

  public void setDescription(String pDescription) {
    getDataObject().setDescription(pDescription);
  }

  public boolean getVerified() {
    return getDataObject().getVerified();
  }

  public void setVerified(boolean pVerified) {
    getDataObject().setVerified(pVerified);
  }

  public DBRef<MongoUser, String> getCreatedByRef() {
    return createdByRef;
  }

  public void setCreatedByRef(DBRef<MongoUser, String> pCreatedBy) {
    // user may have created the category, so we only return id to avoid endless
    // referencing on fetch
    User user = new User();
    user.setId(pCreatedBy.getId());
    getDataObject().setCreatedBy(user);
  }
}
